<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <div>
        <h3>欢迎{{user.nick}}回来!</h3>
        <!--如果isLogin为ture 则显示 退出登录 反之 显示登录-->
        <input v-if="!isLogin" type="button"
               value="登录" @click="login()">
        <div v-if="isLogin">
            <input type="button"
                   value="退出登录" @click="logout()">
            <input type="text" v-model="name">
            <input type="button" value="添加" @click="add()">
        </div>
    </div>
    <ul>
        <li v-for="name in arr" v-text="name"></li>
    </ul>
</div>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    let vm = new Vue({
        el:"body>div",
        data:{/*user变量对应的是一个对象类型里面有nick属性*/
            user:{nick:"张学友"},
            isLogin:false,
            arr:["悟空","八戒","沙僧"],
            name:""
        },
        methods:{
            login:function () {
                vm.isLogin=true;
            },
            logout:function () {
                vm.isLogin=false;
            },
            add:function () {
                //把用户输入的名字添加到
                vm.arr.push(vm.name);
            }
        }
    })
</script>
</body>
</html>